home *** CD-ROM | disk | FTP | other *** search
- /* bt_low2.c - low level functions for BTREE module */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- extern IX_DESC *pci ;
-
- int prev_entry(pb,off) /* back up one entry */
- BLOCK *pb ;
- int off ;
- {
- if( off <= 0 ) /* at start of block ? */
- return( -1 ) ; /* yes - can't back up */
- off = scan_blk(pb,off) ; /* find previous entry */
- return( off ) ;
- }
-
- int next_entry(pb,off) /* go forward one entry */
- BLOCK *pb ;
- int off ;
- {
- if( off >= pb->bend ) /* at end of block ? */
- return( -1 ) ; /* yes - can't go forward */
- off = off + ENT_SIZE(ENT_ADR(pb,off)) ; /* move past entry */
- if( off >= pb->bend ) /* at end of block ? */
- return( -1 ) ; /* yes - no entry here */
- return( off ) ;
- }
-
- int copy_entry(to,from) /* copy an entry */
- ENTRY *to ; /* to this address */
- ENTRY *from ; /* from this address */
- {
- int ne ;
-
- ne = ENT_SIZE(from) ; /* get the entry's size */
- mover(to,from,ne) ; /* move that many bytes */
- }
-
- int scan_blk(pb,n) /* find offset of last entry */
- BLOCK *pb ; /* in this block */
- int n ; /* starting before this position */
- {
- int i , last ;
-
- i = 0 ; last = 0 ;
- while( i < n ) /* repeat until position reached */
- { last = i ; /* save where we are now */
- i = i + ENT_SIZE( ENT_ADR(pb,i) ) ; /* move past entry */
- }
- return( last ) ; /* return last offset < n */
- }
-
- int last_entry(pb) /* find last entry in a block */
- BLOCK *pb ; /* the block */
- {
- /* scan for offset of last entry */
- return( scan_blk(pb,pb->bend) ) ; /* and return the offset */
- }
-
-